//
//  SXStatus.swift
//  sina
//
//  Created by shengxinwei on 16/5/23.
//  Copyright © 2016年 shengxinwei. All rights reserved.
//

import UIKit

class SXStatus: NSObject {
    
    ///微博ID
    var id: Int64 = 0
    
    ///微博创建时间
    var created_at: String?
    
    ///微博信息内容
    var text: String?
    
    ///微博来源
    var source: String?
    
    //用户  直接赋值 会给自定义对象赋值一个字典
    var user: SXUser?
    
    ///转发数
    var reposts_count: Int = 0
    ///评论数
    var comments_count: Int = 0
    ///表态数
    var attitudes_count: Int = 0
    
    //转发微博
    var retweeted_status: SXStatus?
    
    //配图视图的模型数组
    var pic_urls: [SXPicture]?
    


    init(dict: [String: AnyObject]) {
        super.init()
        setValuesForKeysWithDictionary(dict)
    }
    
    override func setValue(value: AnyObject?, forKey key: String) {
        if key == "user" {
            if let dict = value as? [String: AnyObject] {
                user = SXUser(dict: dict)
            }
            return
        }
        
        if key == "retweeted_status" {
            if let dict = value as? [String: AnyObject] {
                retweeted_status = SXStatus(dict: dict)
            }
            return
        }
        
        if key == "pic_urls" {
            if let arr = value as? [[String: AnyObject]] {
                var tmpArr = [SXPicture]()
                for tmp in arr {
                    //字典转模型
                    let s = SXPicture(dict: tmp)
                    tmpArr.append(s)
                }
                pic_urls = tmpArr
            }
            return
        }
        super.setValue(value, forKey: key)
    }
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }
    

}
